package com.neusoft.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.po.CommonResult;
//import com.neusoft.InvalidTokenException;
//import com.neusoft.SecurityConfig;
import com.neusoft.po.Food;
import com.neusoft.service.FoodService;

@RestController
@RequestMapping("/FoodController")
@RefreshScope // 开启动态刷新
public class FoodController {
    @Autowired
    private FoodService foodService;
    // @Autowired
    // private SecurityConfig securityConfig = SecurityConfig.getInstance();

    /*
     * public List<Food> listFoodByBusinessId(@PathVariable("businessId") Integer
     * businessId,
     * 
     * @RequestHeader("token") String token) throws Exception {
     * if (securityConfig.isValidToken(token))
     * return foodService.listFoodByBusinessId(businessId);
     * else
     * throw new InvalidTokenException("Invalid token");
     * }
     */
    @Value("${eureka.instance.lease-renewal-interval-in-seconds}")
    private int renewal;
    @Value("${eureka.instance.lease-expiration-duration-in-seconds}")
    private int exp;

    @GetMapping("/listFoodByBusinessId/{businessId}")
    public CommonResult<List> listFoodByBusinessId(@PathVariable("businessId") Integer businessId) throws Exception {
        System.out.println(renewal);
        System.out.println(exp);
        List<Food> list = foodService.listFoodByBusinessId(businessId);
        return new CommonResult(200, "success", list);
    }

    @GetMapping("/getFoodByFoodId/{foodId}")
    public CommonResult<Food> getFoodByFoodId(@PathVariable("foodId") Integer foodId) throws Exception {
        Food food = foodService.getFoodByFoodId(foodId);
        return new CommonResult(200, "success", food);
    }
}
